package pres.lnk.jxlss.examples;

import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.DateUtil;
import pres.lnk.jxlss.JxlsBuilder;

import java.io.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Demo1 {
    //简单模板导出
    private String templateFilePath = "C:\\project\\jxls\\src\\main\\resources\\Demo1.xlsx";
    private String exPortDir = "C:\\";
    public void exportFile(List<ReconciliationBean> list) throws  Exception {
        // 获取模板目录
        if (StringUtils.isEmpty(templateFilePath)) {
        }
        templateFilePath = templateFilePath.trim();
        InputStream fileInputStream = null;
        OutputStream outputStream = null;
        try {
            // 读取文件
            fileInputStream = new FileInputStream(new File(templateFilePath));
            String fileNameWithPrefix ="CPQYB"+"_TD_" +".csv";
            outputStream = new FileOutputStream(new File(exPortDir + fileNameWithPrefix));
            // 导出
            Map<String, Object> beans = new HashMap<>();
            beans.put("data", list);
            beans.put("length",list.size()+"");
            beans.put("serviceName","CPQYB");
            JxlsBuilder jxlsBuilder = JxlsBuilder
                    .getBuilder(templateFilePath)
                    .out(outputStream)
                    .putAll(beans)
                    .build();
        } finally {
            if (fileInputStream != null) {
                fileInputStream.close();
            }
        }
    }
}
